﻿using View;
using UnityEngine;
using Mediater;
using UnityEngine.Events;
using ZWFrameWork;
using System;
using EventUtils;
using Utilss;

namespace HotFix.Script
{
    public class StartUp
    {
        public static async void Start()
        {
            Utils.OnApplicationPauseCallBack += (pauseStatus) =>
            {
                if (pauseStatus)
                {
                    // 游戏进入暂停状态
                    Debug.Log("Game paused.");
                    EventCenter.BroadCast<bool>(EventUtils.EventType.EVENT_PAUSE_VIEW, pauseStatus);
                    //GameClientManager.Instance().OnApplicationPause(pauseStatus);
                }
                else
                {
                    // 游戏恢复运行状态
                    Debug.Log("Game resumed.");
                    //GameClientManager.Instance().OnApplicationPause(pauseStatus);
                    EventCenter.BroadCast<bool>(EventUtils.EventType.EVENT_PAUSE_VIEW, pauseStatus);
                }
            };
            Utils.OnUpdate += (f) =>
            {
                Timer.Instance.DoUpdate();
                Utils.OnViewUpdate?.Invoke();
            };
            Utils.OnFixUpdate += () =>
            {
                Timer.Instance.DoFixUpdate();
            };
            MediatListerMnager.MediatLister();
            await ResourceManager.Instance.InitializeAsync(HotfixConfig.IsLoadByBundle);
            ConfigManager.Instance.Init();
            // NetManager.Instance.Init();
            Transform transform = Utils.MainBehaviour.gameObject.transform;
            Canvas canvas = transform.GetComponent<Canvas>();
            
            // AndroidManager.Instance().InitData();
            GameObject audio_Obj = ResourceManager.Instance.LoadPrefab("Hall/Prefab/AudioSystem", "AudioSystem");

            GameObject Audio = GameObject.Instantiate(audio_Obj);
            
            UIManager.Instance.Init(canvas);

            GameObject SceenRoot = GameObject.Find("SceneRoot");
            SceenRoot.AddComponent<SceneRootManager>();
            // .Ins.OnInitSDK();
            GameObject adnroidmgrobj = GameObject.Find("AndroidManager");
            var adnroidmgr = adnroidmgrobj.AddComponent<AndroidManager>();
            adnroidmgr.OnInitSDK();
            
            UIManager.Instance.Show(ViewName.LobbyView, ViewLayer.Normal);
        }
    }
}
